﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;

namespace hyjiacan.util.web.wp
{
    internal class ButtonEventHandler
    {
        /// <summary>
        /// 窗体引用
        /// </summary>
        private Form form;

        /// <summary>
        /// 
        /// </summary>
        /// <param name="form">引用的窗体</param>
        public ButtonEventHandler(Form form)
        {
            this.form = form;
        }

        /// <summary>
        /// 绑定点击事件到控件上
        /// </summary>
        /// <param name="button"></param>
        /// <returns>返回类实例以实现链式调用</returns>
        public ButtonEventHandler BindClickEventOn(Button button)
        {
            button.Click += buttonClick;

            return this;
        }

        /// <summary>
        /// 处理主界面的按钮点击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void buttonClick(object sender, EventArgs e)
        {
            // 当前点击的按钮
            Button btn = (Button)sender;

            switch (btn.Name)
            {
                case "bPost":
                    new PostForm(btn.Text).Show();
                    break;
                case "bOption":
                    new OptionForm(btn.Text).Show();
                    break;
                case "bAbout":
                    new AboutForm(btn.Text).ShowDialog(form);
                    break;
                case "bSettings":
                    new SettingsForm("设置").ShowDialog(form);
                    break;
                default:
                    MessageBox.Show(form, "此功能未实现", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    break;
            }
        }
    }
}
